﻿using System;
using UnityEngine;

namespace Miao.Editor
{
    internal class UndoObject : ScriptableObject, ISerializationCallbackReceiver
    {
        public Action onUndo;
        public Action onRedo;

        public int value = 0;

        private int lastValue;

        public void Record()
        {
            value++;
            lastValue = value;
        }

        public void OnAfterDeserialize()
        {
            bool isUndo = value < lastValue;
            lastValue = value;
            if (isUndo) onUndo?.Invoke();
            else onRedo?.Invoke();
        }
        public void OnBeforeSerialize()
        {
        }
    }
}